package jielong

import "time"

const (
	// TableName 表名前缀
	TableNameFix = "youdu_jielong_"
)

type Lists struct {
	ID             uint        `gorm:"primaryKey;comment:主键ID"`
	Theme          string      `gorm:"size:100;not null;comment:接龙主题"`
	Content        string      `gorm:"type:varchar(1024);not null;comment:接龙说明"`
	Fill           string      `gorm:"type:varchar(20);comment:接龙自动填充内容"`
	CreatorAccount string      `gorm:"type:varchar(100);not null;comment:创建者账号"`
	CreatorName    string      `gorm:"type:varchar(100);not null;comment:创建者姓名"`
	VisitTimes     int         `gorm:"default:0;comment:被访问次数"`
	UsersCount     int         `gorm:"default:0;comment:接龙人数"`
	IsOver         bool        `gorm:"default:false;comment:是否结束接龙"`
	CreatedAt      time.Time   `gorm:"autoCreateTime;comment:创建时间"`
	UpdatedAt      time.Time   `gorm:"autoUpdateTime;comment:更新时间"`
	Users          []ListUsers `gorm:"foreignKey:ListID;constraint:OnDelete:CASCADE;"`
}

func (Lists) TableName() string {
	return TableNameFix + "lists"
}

type ListUsers struct {
	ListID      uint      `gorm:"not null"`
	ID          uint      `gorm:"primaryKey;comment:主键ID"`
	Content     string    `gorm:"type:varchar(100);not null;comment:接龙内容"`
	UserAccount string    `gorm:"type:varchar(100);not null;comment:参与人账号"`
	UserName    string    `gorm:"type:varchar(100);not null;comment:参与人姓名"`
	CreatedAt   time.Time `gorm:"autoCreateTime;comment:创建时间"`
	UpdatedAt   time.Time `gorm:"autoUpdateTime;comment:更新时间"`
}

func (ListUsers) TableName() string {
	return TableNameFix + "list_users"
}

type Demo struct {
	ID       uint   `gorm:"primaryKey"`
	Name     string `gorm:"size:100;not null"`
	Email    string `gorm:"type:varchar(100);uniqueIndex;not null"`
	Age      int    `gorm:"default:18"`
	IsActive bool   `gorm:"default:true"`
}

func (Demo) TableName() string {
	return TableNameFix + "demo"
}
